// pages/wenzi-list/wenzi-list.js
var util = require('../../utils/util.js');
var utilMd5 = require('../../utils/md5.js');
var app = getApp();

var ownerId = '';
var loginId = '';

var cataId = '';

var wzPage = 1;
var wzMore = true;
var wzGoinMore = false;

Page({

  /**
   * 页面的初始数据
   */
  data: {
    wzData: []
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    cataId = options.cataid;
    ownerId = options.ownerid;
    wx.setNavigationBarTitle({
      title: options.title,
    })

    app.LoginUserInfo(function (res) {
      if (res != -1) {
        loginId = res.uid;
      }
    }, "");

    this.loadWz(1);
  },

  loadWz: function (cpage) {
    var that = this;
    util.api({
      data: {
        publickey: util.publiccode,
        ac: "topiclist",
        postuid: ownerId,
        topictype: 9,
        toporder: 1,
        albumid:cataId,
        page: cpage,
        num: 20
      },
      success: function (responseData) {
        var result = responseData.data;
        if (result && result.length > 0) {
          result.forEach(function (m, i) {
            if (m.photos)
              result[i].photosData = m.photos.split(",");
          });
          that.setData({
            wzData: that.data.wzData.concat(result)
          });
        } else {
          wzMore = false;
        }
        wzGoinMore = true;
      }
    });
  },

  loadMore: function (e) {
      if (wzMore && wzGoinMore) {
        wzGoinMore = false;
        wzPage++;
        this.loadWz(wzPage);
      } else {
        console.log("文字没有更多了");
      }
  },

  goAtherPage: function (e) {
    var url = e.currentTarget.dataset.link;
    wx.navigateTo({ url: url })
  },

  goAtherPageRedirect: function (e) {
    var url = e.currentTarget.dataset.link;
    wx.redirectTo({ url: url })
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
  
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
  
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
  
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
  
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {
  
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
  
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
  
  }
})